package top.hhydra.mimall.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.hhydra.mimall.service.IProductService;
import top.hhydra.mimall.vo.ProductDetailVo;
import top.hhydra.mimall.vo.ProductVo;
import top.hhydra.mimall.vo.ResponseVo;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author SaiyaEmon
 * @since 2020-02-11
 */
@RestController
@Api(value = "商品controller", tags = {"商品操作接口"})
public class ProductController {

    @Autowired
    IProductService productService;

    @GetMapping("/products")
    @ApiOperation(value = "查询所有商品", notes = "分页查询商品")
    public ResponseVo<IPage<ProductVo>> products(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                 @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                                 @RequestParam(required = false, defaultValue = "0") Integer categoryId) {
        return productService.products(pageNum, pageSize, categoryId);
    }

    @GetMapping("/products/{productId}")
    @ApiOperation(value = "查询单个商品明细", notes = "按照商品id查询商品")
    public ResponseVo<ProductDetailVo> product(@PathVariable Integer productId) {
        return productService.product(productId);
    }

}
